package com.lg.wxq.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lg.wxq.ui.R;

public class MainTabAdapter extends BaseAdapter {
	private Context context;
	private int[] itemIntArray;
	private String[] itemStringArray;
	private boolean[] itemBooleanArray;

	public MainTabAdapter(Context context) {
		this.context = context;
		itemIntArray = new int[] { R.drawable.left_home, R.drawable.left_message, R.drawable.left_friends, R.drawable.left_square, R.drawable.left_search, R.drawable.left_info,
				R.drawable.left_close, R.drawable.left_official_weibo, R.drawable.left_newversions, R.drawable.left_change_accounts };
		itemStringArray = new String[] { "首页", "消息", "好友", "广场", "搜索", "关于", "退出", "官方微博", "新版本检测", "帐号管理" };
		itemBooleanArray = new boolean[] { true, false, false, false, false, false, false, false, false, false };

	}

	public void changeBackGround(int position) {
		for (int i = 0; i < itemBooleanArray.length; i++) {
			itemBooleanArray[i] = (i == position) ? true : false;
		}
		notifyDataSetChanged();
	}

	public int getCount() {
		return itemIntArray.length;
	}

	public Object getItem(int position) {
		return position;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View itemView = null;
		if (convertView != null && convertView.findViewById(R.id.maintablistitem_iv) != null) {
			convertView = null;
		}
		itemView = LayoutInflater.from(context).inflate(R.layout.maintablistitem, null);
		ImageView iv = (ImageView) itemView.findViewById(R.id.maintablistitem_iv);
		iv.setBackgroundResource(itemIntArray[position]);
		TextView tv = (TextView) itemView.findViewById(R.id.maintablistitem_tv);
		tv.setText(itemStringArray[position]);
		itemView.setBackgroundResource(itemBooleanArray[position] ? R.drawable.left_item_bg_check : R.drawable.left_item_bg_uncheck);
		return itemView;
	}

}
